import { createRouter, createWebHistory } from 'vue-router';
import { getCookie } from '../utils';

// 404
import notFound from '../views/error/notFound.vue';
// 首页
import index from '../views/index/index.vue';
// 扎根学校 / 新闻动态
import listSchoolAndNews from '../views/list/schoolAndNews/index.vue';
// 四个共同 / 民族走廊
import listSpace from '../views/list/space/index.vue';
// 知识点列表
import listSpaceList from '../views/list/space/list.vue';
// 知识点详情
import listSpaceDetail from '../views/list/space/detail.vue';

const routes = [
  {
    path: '/:pathMatch(.*)',
    name: 'notFound',
    component: notFound
  },
  {
    path: '/',
    name: 'index',
    component: index
  },
  {
    path: '/listSchoolAndNews',
    name: 'listSchoolAndNews',
    component: listSchoolAndNews
  },
  {
    path: '/listSpace',
    name: 'listSpace',
    component: listSpace
  },
  {
    path: '/listSpaceList',
    name: 'listSpaceList',
    component: listSpaceList
  },
  {
    path: '/listSpaceDetail',
    name: 'listSpaceDetail',
    component: listSpaceDetail
  }
];

const router = createRouter({
  history: createWebHistory('/knowledge-space_v2/'),
  routes: routes,
  scrollBehavior() {
    return { top: 0 };
  }
});

router.beforeEach((to, from, next) => {
  next();
});

export default router;
